/*
 * DoAnJaVaClientView.java
 */
package doanjavaclient;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 * The application's main frame.
 */
public class DoAnJaVaClientView extends FrameView
{

    public static String ip = "";
    static String name = "";
    static String pass = "";
    static String sentSQL = "";
    static String receiveSQL = "";
    private static boolean isSended = false;
    public static boolean isConnectted = false;
    private static String strIP = "localhost";
    private static int iport = 3200;
    private static Socket socketClient;
    private static BufferedWriter bufferedwriter = null;
    private static BufferedReader bufferedreader = null;
    private static DataInputStream datainputstream = null;
    private static ObjectInputStream objectinputstream = null;
    private static InputStream inputstream = null;

    public static void main(String args[])
    {
        DoAnJaVaClientApp app = new DoAnJaVaClientApp();
        app.main(args);
        //phần xử lý giao tiếp và kết nối với server.
        while (true)
        {
            try
            {
                if (isConnectted)
                {
                    //neu click net send SQL query
                    if (isSended)
                    {
                        inputstream = socketClient.getInputStream();
                        bufferedreader = new BufferedReader(new InputStreamReader(inputstream));
                        bufferedwriter = new BufferedWriter(new OutputStreamWriter(socketClient.getOutputStream()));
                        objectinputstream = new ObjectInputStream(inputstream);
//                        objectinputstream = new ObjectInputStream(new BufferedInputStream(inputstream));
                        sentSQL = tfSql.getText();
                        bufferedwriter.write(sentSQL);
                        bufferedwriter.newLine();
                        bufferedwriter.flush();
                        isSended = false;
                        if (sentSQL.equals("quit"))
                            break;
                        else
                        {
                            //goi ham truy van chuoi SQL de truy van CSDL, va tra ve ket qua la 1 JTable
                            JTable table = (JTable)objectinputstream.readObject();
                            if (table == null)
                            {
                                lbresult.setText("SQL query fail!");
                                scrollPaneResult.setViewportView(lbresult);
                            }
                            else
                            {
                                scrollPaneResult.setViewportView(table);
                            }
                        }
                    }
                }
            } catch (Exception ex)
            {
                System.out.println(ex.getMessage());
            }
        }
    }

    public DoAnJaVaClientView(SingleFrameApplication app)
    {
        super(app);

        initComponents();
        //an di cac thanh phan khac neu nhu client chua connect den server
        disableComponents();
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++)
        {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener()
        {

            public void propertyChange(java.beans.PropertyChangeEvent evt)
            {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName))
                {
                    if (!busyIconTimer.isRunning())
                    {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                }
                else if ("done".equals(propertyName))
                {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                }
                else if ("message".equals(propertyName))
                {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                }
                else if ("progress".equals(propertyName))
                {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox()
    {
        if (aboutBox == null)
        {
            JFrame mainFrame = DoAnJaVaClientApp.getApplication().getMainFrame();
            aboutBox = new DoAnJaVaClientAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        DoAnJaVaClientApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        tfPassword = new javax.swing.JTextField();
        tfIP = new javax.swing.JTextField();
        tfUserName = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btnConnect = new javax.swing.JButton();
        tfSql = new javax.swing.JTextField();
        btnSend = new javax.swing.JButton();
        scrollPaneResult = new javax.swing.JScrollPane();
        lbresult = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(doanjavaclient.DoAnJaVaClientApp.class).getContext().getResourceMap(DoAnJaVaClientView.class);
        tfPassword.setFont(resourceMap.getFont("tfPassword.font")); // NOI18N
        tfPassword.setForeground(resourceMap.getColor("tfPassword.foreground")); // NOI18N
        tfPassword.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, resourceMap.getColor("tfPassword.border.matteColor"))); // NOI18N
        tfPassword.setName("tfPassword"); // NOI18N
        tfPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfPasswordActionPerformed(evt);
            }
        });

        tfIP.setFont(resourceMap.getFont("tfIP.font")); // NOI18N
        tfIP.setForeground(resourceMap.getColor("tfIP.foreground")); // NOI18N
        tfIP.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, resourceMap.getColor("tfIP.border.matteColor"))); // NOI18N
        tfIP.setName("tfIP"); // NOI18N

        tfUserName.setFont(resourceMap.getFont("tfUserName.font")); // NOI18N
        tfUserName.setForeground(resourceMap.getColor("tfUserName.foreground")); // NOI18N
        tfUserName.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, resourceMap.getColor("tfUserName.border.matteColor"))); // NOI18N
        tfUserName.setName("tfUserName"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel5.setForeground(resourceMap.getColor("jLabel5.foreground")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel4.setForeground(resourceMap.getColor("jLabel4.foreground")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setForeground(resourceMap.getColor("jLabel3.foreground")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        btnConnect.setText(resourceMap.getString("btnConnect.text")); // NOI18N
        btnConnect.setName("btnConnect"); // NOI18N
        btnConnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConnectActionPerformed(evt);
            }
        });

        tfSql.setBackground(resourceMap.getColor("tfSql.background")); // NOI18N
        tfSql.setForeground(resourceMap.getColor("tfSql.foreground")); // NOI18N
        tfSql.setText(resourceMap.getString("tfSql.text")); // NOI18N
        tfSql.setToolTipText(resourceMap.getString("tfSql.toolTipText")); // NOI18N
        tfSql.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, resourceMap.getColor("tfSql.border.matteColor"))); // NOI18N
        tfSql.setName("tfSql"); // NOI18N

        btnSend.setText(resourceMap.getString("btnSend.text")); // NOI18N
        btnSend.setName("btnSend"); // NOI18N
        btnSend.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSendActionPerformed(evt);
            }
        });

        scrollPaneResult.setBackground(resourceMap.getColor("scrollPaneResult.background")); // NOI18N
        scrollPaneResult.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, resourceMap.getColor("scrollPaneResult.border.matteColor"))); // NOI18N
        scrollPaneResult.setToolTipText(resourceMap.getString("scrollPaneResult.toolTipText")); // NOI18N
        scrollPaneResult.setEnabled(false);
        scrollPaneResult.setName("scrollPaneResult"); // NOI18N

        lbresult.setFont(resourceMap.getFont("lbresult.font")); // NOI18N
        lbresult.setForeground(resourceMap.getColor("lbresult.foreground")); // NOI18N
        lbresult.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbresult.setText(resourceMap.getString("lbresult.text")); // NOI18N
        lbresult.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        lbresult.setName("lbresult"); // NOI18N
        scrollPaneResult.setViewportView(lbresult);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(tfUserName)
                    .addComponent(tfIP, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                    .addComponent(tfPassword))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnConnect, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSend))
                .addContainerGap(297, Short.MAX_VALUE))
            .addComponent(tfSql, javax.swing.GroupLayout.DEFAULT_SIZE, 740, Short.MAX_VALUE)
            .addComponent(scrollPaneResult, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 740, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tfIP, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnConnect))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(btnSend))
                .addGap(18, 18, 18)
                .addComponent(tfSql, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(scrollPaneResult, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(doanjavaclient.DoAnJaVaClientApp.class).getContext().getActionMap(DoAnJaVaClientView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 740, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 570, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

private void tfPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfPasswordActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_tfPasswordActionPerformed

private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
// TODO add your handling code here:
    try
    {
        // TODO add your handling code here:
        sentSQL = btnConnect.getText();
        //neu khi nhan nut "Connect"
        if ("Connect".equals(btnConnect.getText()))
        {
            //doi thay nut "Disconnect"
            btnConnect.setText("Disconnect");
            sentSQL = "Connect";
            //strIP = jTextField1.getText();
            System.out.println("Client IP = " + strIP);
            //thuc hien connect toi server
            enableComponents();
            connectToServer();
            isConnectted = true;
        }
        //neu nhan nut disconnect thi thuc hien ngat ket noi den server
        else
        {
            btnConnect.setText("Connect");
            sentSQL = "Disconnect";
            disableComponents();
            isConnectted = false;
            bufferedwriter.close();
            bufferedreader.close();
            datainputstream.close();
            System.out.println("Client has left!");
            socketClient.close();
        }
    } catch (IOException ex)
    {
        Logger.getLogger(DoAnJaVaClientView.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_btnConnectActionPerformed

private void btnSendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendActionPerformed
// TODO add your handling code here:
    isSended = true;
    sentSQL = tfSql.getText();
    if (sentSQL.equals("quit"))
    {
        disableComponents();
        btnConnect.setText("Connect");
    }
}//GEN-LAST:event_btnSendActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnConnect;
    private javax.swing.JButton btnSend;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private static javax.swing.JLabel lbresult;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    protected static javax.swing.JScrollPane scrollPaneResult;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private static javax.swing.JTextField tfIP;
    private static javax.swing.JTextField tfPassword;
    private static javax.swing.JTextField tfSql;
    public static javax.swing.JTextField tfUserName;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;

    private void disableComponents()
    {
        tfSql.setEnabled(false);
        scrollPaneResult.setEnabled(false);
        btnSend.setEnabled(false);
    }

    private void enableComponents()
    {
        tfSql.setEnabled(true);
        scrollPaneResult.setEnabled(true);
        btnSend.setEnabled(true);
    }

    public void connectToServer()
    {
        try
        {
            //tao 1 socket o phia client co IP la "locallhost" va port = 3200
            socketClient = new Socket(strIP, iport);
            bufferedreader = new BufferedReader(new InputStreamReader(socketClient.getInputStream()));
            bufferedwriter = new BufferedWriter(new OutputStreamWriter(socketClient.getOutputStream()));
            datainputstream = new DataInputStream(socketClient.getInputStream());

            System.out.println("Talking to Server");
            //gan gia tri ket noi cho moi bien
            ip = tfIP.getText();
            name = tfUserName.getText();
            pass = tfPassword.getText();
            //client goi IP qua server de kiem tra
            bufferedwriter.write(ip);
            bufferedwriter.newLine();
            bufferedwriter.flush();
            //client goi user name qua server de kiem tra
            bufferedwriter.write(name);
            bufferedwriter.newLine();
            bufferedwriter.flush();
            //client goi password qua server de kiem tra
            bufferedwriter.write(pass);
            bufferedwriter.newLine();
            bufferedwriter.flush();
            //nhan thong bao pass hoac fail
            String strTempResult = bufferedreader.readLine();
            if (strTempResult.equals("fail"))
            {
                JOptionPane.showMessageDialog(this.getComponent(), "Fail connected!");
                btnConnect.setText("Connect");
                disableComponents();
            }
            else if (strTempResult.equals("pass"))
            {
                JOptionPane.showMessageDialog(this.getComponent(), "Pass connected!");
            }
            else
            {
                JOptionPane.showMessageDialog(this.getComponent(), "Fail connected!");
                btnConnect.setText("Connect");
            }

        } catch (UnknownHostException ex)
        {
            Logger.getLogger(DoAnJaVaClientView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex)
        {
            Logger.getLogger(DoAnJaVaClientView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
